package data

import (
	"go-graduation/service/internal/data/PO"
)

type article struct {
}

func NewArticle() *article {
	return &article{}
}

func (a *article) GetOneById(id int) (PO.Article, error) {
	var row PO.Article
	err := NewDBClient().Table(PO.ArticleTableName).Where("id = ?", id).Limit(1).Find(&row).Error
	return row, err
}

func (a *article) GetListByPage(pageStart int, limit int) ([]PO.Article, error) {
	var rows []PO.Article
	err := NewDBClient().Table(PO.ArticleTableName).Select("id").Offset(pageStart).Limit(limit).Find(&rows).Error
	return rows, err
}

func (a *article) GetListByIds(ids []int) ([]PO.Article, error) {
	var rows []PO.Article
	err := NewDBClient().Table(PO.ArticleTableName).Where("id IN (?)", ids).Find(&rows).Error
	return rows, err
}
